package com.heba.fragment.diary;

import android.content.res.Resources;
import android.location.Location;
import android.os.Bundle;
import androidx.annotation.Nullable;

import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.facebook.common.Common;
import com.google.android.material.tabs.TabLayout;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.heba.Cfg;
import com.heba.adapter.FmPagerAdapter;
import com.heba.adapter.diary.DiaryListRecyclerAdapter;
import com.heba.adapter.diary.DiaryThreeFragment;
import com.heba.adapter.diary.callback.DiaryItemListener;
import com.heba.bean.ItemShareObject;
import com.heba.bean.ShareObject;
import com.heba.bean.diary.ItemDiaryDetailObject;
import com.heba.config.CommonConfig;
import com.heba.dialog.CustomDialogView;
import com.heba.event.MessageEvent;
import com.heba.fragment.BaseFragment;
import com.heba.fragment.scan.BarScanFragment;
import com.heba.fragment.scan.HistoryScanFragment;
import com.heba.fragment.scan.SavedScanFragment;
import com.heba.greenmulu.ItemReportActivity;
import com.heba.greenmulu.R;
import com.heba.greenmulu.diary.ItemDiaryAddActivity;
import com.heba.greenmulu.diary.ItemDiarySearchActivity;
import com.heba.greenmulu.diary.ItemDiarySearchNewActivity;
import com.heba.helper.HttpClientHelper;
import com.heba.helper.JSONHttpHelper;
import com.heba.helper.MemberShipHelper;
import com.heba.popupwindow.DiaryCommentPopupWindow;
import com.heba.popupwindow.OpenMapPopupWindow;
import com.heba.popupwindow.SharePopupWindow;
import com.heba.popupwindow.callback.OpenMapClickListener;
import com.heba.popupwindow.callback.ShareListener;
import com.heba.utils.IndicatorLineUtil;
import com.heba.utils.ToastShow;
import com.heba.view.ClearEditTextView;
import com.loopj.android.http.RequestParams;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 日记页面
 * Created by jason on 2020/1/7.
 */
public class DiaryFragment extends BaseFragment {

    private View view_background;
    private View topbar;
    private ClearEditTextView clearEditTextView;
    private ImageView iv_diary;
    private ConstraintLayout bottomLine1;
    private int selectIndex = 0;
//    private SmartRefreshLayout refreshLayout;
//    private RecyclerView recyclerView;
//    private DiaryListRecyclerAdapter recycleAdapter;

    private TabLayout tabLayout;
    private DiaryThreeFragment exlporeDiaryFragment;
    private DiaryThreeFragment followDiaryFragment;
    private DiaryThreeFragment nearbyDiaryFragment;
    private ViewPager diaryViewPager;
    private FmPagerAdapter diaryAdapter;
    private List<Fragment> fragments = new ArrayList<>();

    /**
     * 打開地圖彈出框
     */
    private OpenMapPopupWindow openMapPopupWindow;

    /**
     * 分享彈出框
     */
    private SharePopupWindow sharePopupWindow;
    private ShareObject shareObject;

    /**
     * 評論彈出框
     */
    private DiaryCommentPopupWindow commentPopupWindow;

    /**
     * 日记列表数据
     */
    private List<ItemDiaryDetailObject> diaryDetailObjectList;

    /**
     * 添加评论参数
     */
    private int currentPos;     //每個item的position
    private String diaryID;   //每個item的日記id
    private int type;     //判斷評論回復
    private String feedbackID;
    private String toUserID;

    private boolean isDiaryCollect;  //日記是否收藏

    private int diaryType = 0;     //类型 主页显示还是搜索显示
    private String keyWord = "";    //搜索关键字

    private String[] tabStrings;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    /**
     * 实例化fragment
     * 接收参数
     *
     * @param keyWord
     * @return
     */
    public static DiaryFragment newInstance(int type, String keyWord) {
        DiaryFragment fragment = new DiaryFragment();
        Bundle bundle = new Bundle();
        bundle.putInt(CommonConfig.TYPE, type);
        bundle.putString(CommonConfig.KEYWORD, keyWord);
        fragment.setArguments(bundle);
        return fragment;
    }

    /**
     * 取出参数
     */
    private void parseArgument() {
        Bundle bundle = getArguments();
        if (null != bundle) {
            diaryType = bundle.getInt(CommonConfig.TYPE, 0);
            keyWord = bundle.getString(CommonConfig.KEYWORD, "");
        }
    }

    @Override
    public void onResume() {
        super.onResume();

        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.diarythree_ragment, container, false);

        parseArgument();
        initOpenMapWindow();
        initView(view);
//        initPopupWindow();

//        getDiaryListData();
        return view;
    }

    /**
     * initView
     *
     * @param view
     */
    private void initView(View view) {
        view_background = view.findViewById(R.id.view_background);
        topbar = view.findViewById(R.id.topbar);
        clearEditTextView = view.findViewById(R.id.clearEditText);
        iv_diary = view.findViewById(R.id.img_left);
//        refreshLayout = view.findViewById(R.id.refreshLayout);
//        recyclerView = view.findViewById(R.id.recyclerView);
        exlporeDiaryFragment = new DiaryThreeFragment();
        exlporeDiaryFragment.loadUrl = CommonConfig.DIARY_EXPLORE_LIST;
        nearbyDiaryFragment = new DiaryThreeFragment();
        nearbyDiaryFragment.loadUrl = CommonConfig.DIARY_NEARBY_LIST;
        followDiaryFragment = new DiaryThreeFragment();
        followDiaryFragment.loadUrl = CommonConfig.DIARY_FOLLOW_LIST;

        exlporeDiaryFragment.setView_background(view_background);
        nearbyDiaryFragment.setView_background(view_background);
        followDiaryFragment.setView_background(view_background);




        exlporeDiaryFragment.openMapPopupWindow = openMapPopupWindow;
        nearbyDiaryFragment.openMapPopupWindow = openMapPopupWindow;
        followDiaryFragment.openMapPopupWindow = openMapPopupWindow;

        tabLayout = view.findViewById(R.id.diary_tabLayout);
        diaryViewPager = view.findViewById(R.id.diary_viewpager);
        fragments.add(exlporeDiaryFragment);
        fragments.add(followDiaryFragment);
        fragments.add(nearbyDiaryFragment);

        diaryAdapter = new FmPagerAdapter(fragments,getFragmentManager());
        diaryViewPager.setAdapter(diaryAdapter);
        diaryViewPager.setOffscreenPageLimit(3);
        ///設置title
        tabStrings = getActivity().getResources().getStringArray(R.array.array_diary_list);
        for (int i = 0; i < tabStrings.length; i++) {
            tabLayout.addTab(tabLayout.newTab());
        }
        tabLayout.setupWithViewPager(diaryViewPager);
        for (int i = 0 ;i<tabStrings.length;i++){
            tabLayout.getTabAt(i).setText(tabStrings[i]);
        }
        tabLayout.getTabAt(0).select();
        bottomLine1 = view.findViewById(R.id.bottom_line_1);
        /**
        * 设置指示线长度间隔(单位dp)
        */
        tabLayout.post(new Runnable() {
            @Override
            public void run() {
                IndicatorLineUtil.setIndicator(tabLayout, 0, 0);
            }
        });
        TextView title = (TextView) (((LinearLayout) ((LinearLayout) tabLayout.getChildAt(0)).getChildAt(0)).getChildAt(1));
        title.setTextAppearance(R.style.TabLayoutSelectedTextStyle1);
        /**
         * tabLayout监听滑动指示卡
         */
        tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                int position = tabLayout.getSelectedTabPosition();
                Resources resources = getResources();
                DisplayMetrics dm = resources.getDisplayMetrics();
                int width3 = dm.widthPixels;
                TextView title = (TextView) (((LinearLayout) ((LinearLayout) tabLayout.getChildAt(0)).getChildAt(tab.getPosition())).getChildAt(1));
                title.setTextAppearance(R.style.TabLayoutSelectedTextStyle1);
                TranslateAnimation translateAnimation1 = new TranslateAnimation((selectIndex)*(width3/3),(position)*(width3/3),0,0);
                translateAnimation1.setDuration(300);
                translateAnimation1.setFillEnabled(true);//使其可以填充效果从而不回到原地
                translateAnimation1.setFillAfter(true);//不回到起始位置
                bottomLine1.startAnimation(translateAnimation1);


                translateAnimation1.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        selectIndex = tabLayout.getSelectedTabPosition();

                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }
                });
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                TextView title = (TextView) (((LinearLayout) ((LinearLayout) tabLayout.getChildAt(0)).getChildAt(tab.getPosition())).getChildAt(1));
                title.setTextAppearance(R.style.TabLayoutNormalTextStyle1);
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
        if (diaryType == 1) {
            topbar.setVisibility(View.GONE);
        } else {
            topbar.setVisibility(View.VISIBLE);
        }

        clearEditTextView.setTextHint(getActivity().getResources().getString(R.string.diary_search_title));
        shareObject = new ShareObject();

        //点击edittex跳转
        clearEditTextView.clearFocus();
        clearEditTextView.setOnEditTextListener(new ClearEditTextView.OnEditTextListener() {
            @Override
            public void onDeleteClick() {

            }

            @Override
            public void afterTextChanged(String text) {

            }

            @Override
            public void onSearchClick(String text) {

            }

            @Override
            public void onIntent() {
                openActivity(ItemDiarySearchNewActivity.class);
            }
        });

        diaryDetailObjectList = new ArrayList<>();

//        recycleAdapter = new DiaryListRecyclerAdapter(getContext(), diaryDetailObjectList);

//        recycleAdapter.setDiaryItemListener(new DiaryItemListener() {
//            @Override
//            public void showSharePopup(View view, int position, ItemDiaryDetailObject object) {
//                view_background.setVisibility(View.VISIBLE);
//                currentPos = position;
//                isDiaryCollect = object.getIsCollected() == 1;
//                diaryID = object.getDiaryID();
//                shareObject.setShareTitle(String.format(getContext().getResources().getString(R.string.share_diary_title), object.getAccount()));
//                shareObject.setShareContent(object.getContent());
//                if (object.getImageList() != null && !object.getImageList().isEmpty())
//                    shareObject.setShareImageUrl(object.getImageList().get(0).getImageUrl());
//                shareObject.setShareLink(object.getLink());
//                sharePopupWindow.setShareObject(shareObject);
//                if (Cfg.UserID.equals(object.getUserID())) {
//                    sharePopupWindow.setShareList(updateShareList1(), updateShareList2(true));
//                } else {
//                    sharePopupWindow.setShareList(updateShareList1(), updateShareList2(false));
//                }
//                sharePopupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
//            }
//
//            @Override
//            public void showCommentPopup(View view, String diaryid, String userid) {
//                diaryID = diaryid;
//                type = 0;
//                feedbackID = "";
//                toUserID = userid;
//                showCommentPopupView(view, type, feedbackID, toUserID, getResources().getString(R.string.diary_comment));
//            }
//        });

        /**
         * 设置layoutManager布局
         */
//        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
//        //设置布局管理器
//        recyclerView.setLayoutManager(layoutManager);
//        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
//        //设置Adapter
//        recyclerView.setAdapter(recycleAdapter);
//        //设置动画执行时间为0  防止局部刷新时闪烁
//        recyclerView.getItemAnimator().setChangeDuration(0);
//
//        //设置是否监听滚动到底部是触发自动刷新
//        refreshLayout.setEnableAutoLoadMore(false);
//
//        /**
//         * 处理下拉刷新事件
//         */
//        refreshLayout.setOnRefreshListener(refreshLayout -> {
//            Page = 1;
//            isRefreshFromTop = true;
//            getDiaryListData();
//        });
//
//        /**
//         * 处理上拉加载事件
//         */
//        refreshLayout.setOnLoadMoreListener(refreshLayout -> {
//            Page++;
//            isRefreshFromTop = false;
//            getDiaryListData();
//        });

        /**
         * 新增日記
         */
        iv_diary.setOnClickListener(v -> openActivity(ItemDiaryAddActivity.class));
    }
    /**
     * 打開地圖彈出框
     */
    private  void initOpenMapWindow(){
        openMapPopupWindow = new OpenMapPopupWindow(getActivity(),ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        openMapPopupWindow.setOpenMapClickListener(new OpenMapClickListener(getContext()){
            @Override
            public void openGoogleMap(ItemDiaryDetailObject diaryDetailObject, Location mLocation) {
                super.openGoogleMap(diaryDetailObject, mLocation);
            }

            @Override
            public void onCancelClick() {
                super.onCancelClick();
            }

            @Override
            public void onOpenAppleMap() {
            }
        });
        openMapPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                view_background.setVisibility(View.GONE);
            }
        });
    }
    /**
     * 分享彈出框
     */
    private void initPopupWindow() {

        sharePopupWindow = new SharePopupWindow(getActivity(), ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        sharePopupWindow.setShareList(updateShareList1(), updateShareList2(false));

        /**
         * 分享接口實現
         */
        sharePopupWindow.setOnShareListener(new ShareListener(getContext()) {
            @Override
            public void collectDiary() {
                /**
                 * 收藏日記貼
                 */
                if (isDiaryCollect) {
                    ToastShow.displayToast(getActivity(), getResources().getString(R.string.diary_has_been_collect));
                    return;
                }
                new MemberShipHelper(new MemberShipHelper.MembershipListener() {
                    @Override
                    public void Success() {
                        ToastShow.displayToast(getActivity(), getResources().getString(R.string.diary_collect_success));
                    }

                    @Override
                    public void Fail(String error) {

                    }
                }).collectDiary(getActivity(), diaryID);
            }

            @Override
            public void reportDiary() {
                Bundle bundle = new Bundle();
                bundle.putInt(CommonConfig.TYPE, 2);
                bundle.putString(CommonConfig.REPORT_ID, diaryID);
                openActivity(ItemReportActivity.class, bundle);
            }

            @Override
            public void deleteDiary() {
                /**
                 * 删除日记
                 */
                new CustomDialogView(new CustomDialogView.OnCustomDialogClickListener() {
                    @Override
                    public void onYesClick() {
                        progressDialog.show();
                        new MemberShipHelper(new MemberShipHelper.MembershipListener() {
                            @Override
                            public void Success() {
                                progressDialog.dismiss();
                                diaryDetailObjectList.remove(currentPos);
//                                recycleAdapter.notifyItemRemoved(currentPos);
                                ToastShow.displayToast(getContext(), getContext().getResources().getString(R.string.diary_delete_success));
                            }

                            @Override
                            public void Fail(String error) {
                                progressDialog.dismiss();
                            }
                        }).deleteDiary(getActivity(), diaryID);
                    }

                    @Override
                    public void onNoClick() {

                    }
                }).showDialog(getActivity(), getResources().getString(R.string.diary_delete_tips), "");
            }
        });

        sharePopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                view_background.setVisibility(View.GONE);
            }
        });

        /**
         * 評論彈出框
         */
        commentPopupWindow = new DiaryCommentPopupWindow(getActivity(), ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        commentPopupWindow.setOnDiaryCommentListener(content -> {
            /**
             * 用户留言处理
             */
            progressDialog.show();
            new MemberShipHelper(new MemberShipHelper.MembershipListener() {
                @Override
                public void Success() {
                    /**
                     * 留言评论成功，更新数据
                     */
                    progressDialog.dismiss();
                    commentPopupWindow.setCommentHint(getResources().getString(R.string.diary_comment));
                    commentPopupWindow.setCommentText("");
//                    refreshDiaryListData();
                }

                @Override
                public void Fail(String error) {
                    progressDialog.dismiss();
                }
            }).addFeedback(getActivity(), diaryID, type, content, toUserID, feedbackID);
        });
        commentPopupWindow.setOnDismissListener(() -> view_background.setVisibility(View.GONE));


        exlporeDiaryFragment.setCommentPopupWindow(commentPopupWindow);
        nearbyDiaryFragment.setCommentPopupWindow(commentPopupWindow);
        followDiaryFragment.setCommentPopupWindow(commentPopupWindow);

        exlporeDiaryFragment.setSharePopupWindow(sharePopupWindow);
        nearbyDiaryFragment.setSharePopupWindow(sharePopupWindow);
        followDiaryFragment.setSharePopupWindow(sharePopupWindow);

        exlporeDiaryFragment.setShareObject(shareObject);
        nearbyDiaryFragment.setShareObject(shareObject);
        followDiaryFragment.setShareObject(shareObject);
    }

    /**
     * 分享至社交軟件
     */
    private List<ItemShareObject> updateShareList1() {
        List<ItemShareObject> shareList = new ArrayList<>();
        int[] ids = {R.drawable.icon_more_share_facebook, R.drawable.icon_more_share_whatsapp, R.drawable.icon_more_share_wechat, R.drawable.icon_more_share_friends};
        String[] contents = getActivity().getResources().getStringArray(R.array.share_contents_normal);
        int[] shareTypes = {CommonConfig.SHARE_TO_FACEBOOK, CommonConfig.SHARE_TO_WHATSAPP, CommonConfig.SHARE_TO_WECHAT, CommonConfig.SHARE_TO_CIRCLE};
        for (int i = 0; i < ids.length; i++) {
            ItemShareObject shareObject = new ItemShareObject();
            shareObject.setImageID(ids[i]);
            shareObject.setShareContent(contents[i]);
            shareObject.setShareType(shareTypes[i]);
            shareList.add(shareObject);
        }
        return shareList;
    }

    /**
     * 本地分享
     *
     * @param withDiaryDelete 是否包含删除日记
     * @return
     */
    private List<ItemShareObject> updateShareList2(boolean withDiaryDelete) {
        List<ItemShareObject> shareList = new ArrayList<>();
        int[] ids1 = {R.drawable.icon_more_collection, R.drawable.icon_more_report, R.drawable.icon_more_delete};
        String[] contents1 = getActivity().getResources().getStringArray(R.array.share_contents_diary);
        int[] shareTypes1 = {CommonConfig.SHARE_TO_COLLECT_DIARY, CommonConfig.SHARE_TO_REPORT_DIARY, CommonConfig.SHARE_TO_DELETE_DIARY};
        int len = ids1.length;
        if (!withDiaryDelete) {
            len = ids1.length - 1;
        }
        for (int i = 0; i < len; i++) {
            ItemShareObject shareObject = new ItemShareObject();
            shareObject.setImageID(ids1[i]);
            shareObject.setShareContent(contents1[i]);
            shareObject.setShareType(shareTypes1[i]);
            shareList.add(shareObject);
        }
        return shareList;
    }

    /**
     * 显示评论弹出框
     *
     * @param view
     * @param type      判断是日记留言 还是回复用户留言
     * @param commentID 回复用户留言ID
     * @param toUserID  回复目标用户ID
     * @param hint      输入框提示
     */
    private void showCommentPopupView(View view, int type, String commentID, String toUserID, String hint) {
        this.type = type;
        this.feedbackID = commentID;
        this.toUserID = toUserID;
        view_background.setVisibility(View.VISIBLE);
        commentPopupWindow.setCommentHint(hint);
        commentPopupWindow.showSoftKeyBoard();
        commentPopupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
    }

    /**
     * 获取日记列表数据
     */
//    private void getDiaryListData() {
//        if (firstRefresh) {
//            progressDialog.show();
//            firstRefresh = false;
//        }
//        HttpClientHelper client = new HttpClientHelper();
//        client.setUseLogin(true);
//        RequestParams params = new RequestParams();
//        params.put("Leng", Cfg.Leng);
//        params.put("p", Page);
//        params.put("pp", PerPage);
//        params.put("Type", 1);
//        params.put("Keyword", keyWord);
//        client.get(Cfg.BaseUrl + "/Diary/DiaryListing", params,
//                new JSONHttpHelper.JSONHttpResponseHandler(getActivity()) {
//
//                    @Override
//                    public void Success() {
//                        // TODO Auto-generated method stub
//                        super.Success();
//                        progressDialog.dismiss();
//                        closeRefreshView(refreshLayout);
//
//                        /**
//                         * 下拉刷新处理
//                         */
//                        if (isRefreshFromTop) {
//                            isRefreshFromTop = false;
//                            refreshLayout.setNoMoreData(false);
//                            diaryDetailObjectList.clear();
//                        }
//
//                        try {
//                            JSONArray array = new JSONObject(response.trim()).getJSONArray("Result");
//                            if (array.length() > 0) {
//                                List<ItemDiaryDetailObject> diaryDetailObjects = new Gson().fromJson(array.toString(), new TypeToken<List<ItemDiaryDetailObject>>() {
//                                }.getType());
//                                diaryDetailObjectList.addAll(diaryDetailObjectList.size(), diaryDetailObjects);
//                            } else {
//                                //无数据
//                                refreshLayout.finishLoadMoreWithNoMoreData();
//                            }
//                        } catch (JSONException e) {
//                            e.printStackTrace();
//                        }
//
//                        //刷新数据
//                        recycleAdapter.notifyDataSetChanged();
//                    }
//
//                    public void Failure() {
//                        super.Failure();
//                        progressDialog.dismiss();
//                        closeRefreshView(refreshLayout);
//                    }
//
//                });
//    }
//
//    /**
//     * 刷新日記列表數據
//     */
//    private void refreshDiaryListData() {
//        Page = 1;
//        isRefreshFromTop = true;
//        getDiaryListData();
//    }
//
//    /**
//     * 接收EventBus
//     *
//     * @param event
//     */
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(MessageEvent event) {
        /**
         * 更新列表數據
         */
        if (event.getEvent().equals(CommonConfig.EVENT_REFRESH_DIARY_LIST)) {
//            refreshDiaryListData();
        }

        /**
         * 浏览探索页时，点击探索页icon返回最顶并刷新数据
         */
        if (event.getEvent().equals(CommonConfig.EVENT_MAIN_CLICK_REFRESH_DIARY_LIST)) {
            if (isVisible) {
//                recyclerView.scrollToPosition(0);
//                refreshLayout.autoRefresh();
            }
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        //反註冊
        EventBus.getDefault().unregister(this);
    }
}
